<?php 

	include("includes/connect_db.php"); 

	$searchKey = $_POST['key'];
	switch ($_GET["act"]) {
		case 1:
			$sql = "SELECT * FROM (SELECT a.id_kontak AS id, a.nama_kontak AS nama, 'a' AS tipe FROM tb_kontak a UNION SELECT b.id_group AS id, b.nama_group AS nama, 'b' AS tipe FROM tb_group_kontak b) AS tb_comb WHERE nama LIKE '%".$searchKey."%'";
            $sql .= " ORDER BY nama ASC LIMIT 5";
            $query = mysql_query($sql);
            while ($baris = mysql_fetch_array($query)) {
              $data[] = array("id"=>$baris['id'],"nama"=>$baris['nama'],"tipe"=>$baris["tipe"]);
            }
            echo json_encode($data);
            break;
	}

?>